Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

feat: query caching plugin#608

Closed
sanny-io wants to merge 14 commits into
zenstackhq:devfrom
sanny-io:feat/cache-plugin
Closed

feat: query caching plugin#608
sanny-io wants to merge 14 commits into
zenstackhq:devfrom
sanny-io:feat/cache-plugin

Conversation

@sanny-io
Copy link
Copy Markdown
Contributor

@sanny-io sanny-io commented Jan 20, 2026

Sample Usage

import { defineCachePlugin } from '@zenstackhq/plugin-cache'
import { MemoryCache } from '@zenstackhq/plugin-cache/providers/memory'

...

const extDb = db.$use(defineCachePlugin({
    provider: new MemoryCache(),
}))

const users = await extDb.user.findMany({
    cache: {
        ttl: 60,
        tags: ['all-users'],
    },
})

await extDb.$cache.invalidate({
    tags: ['all-users'],
})

await extDb.$cache.invalidateAll()
const users = await extDb.user.findMany({
    cache: {
        swr: 60,
    },
})

const usersCacheStatus = extDb.$cache.status // 'hit' | 'miss' | 'stale'

await extDb.$cache.revalidation // if stale, waits for it to be revalidated

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 20, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.


onQuery: async ({ args, model, operation, proceed }) => {
if (args && 'cache' in args) {
const json = stableStringify({
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cache options is now part of the cache key. I guess it's fine, just wanted to make sure it's intentional.


onQuery: async ({ args, model, operation, proceed }) => {
if (args && 'cache' in args) {
const json = stableStringify({
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cache options is now part of the cache key. I guess it's fine, just wanted to make sure it's intentional.

@sanny-io sanny-io closed this Jan 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants